aboutsummaryrefslogtreecommitdiffstats
path: root/src/app/groups/[groupId]/edit/page.tsx
blob: f902428df0df03af545fb18f64d0c96e5faec58d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import { GroupForm } from '@/components/group-form'
import { getGroup, updateGroup } from '@/lib/api'
import { groupFormSchema } from '@/lib/schemas'
import { notFound, redirect } from 'next/navigation'

export default async function EditGroupPage({
  params: { groupId },
}: {
  params: { groupId: string }
}) {
  const group = await getGroup(groupId)
  if (!group) notFound()

  async function updateGroupAction(values: unknown) {
    'use server'
    const groupFormValues = groupFormSchema.parse(values)
    const group = await updateGroup(groupId, groupFormValues)
    redirect(`/groups/${group.id}`)
  }

  return <GroupForm group={group} onSubmit={updateGroupAction} />
}